﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Business.Models;
using System.Data;

namespace Business.DAO
{
    public class HocSinhDAO
    {
        private ISSContext db = new ISSContext();
        public List<HocSinh> GetAll()
        {
            return db.HocSinh.ToList();
        }

        public HocSinh Get(int id)
        {
            HocSinh HocSinh = db.HocSinh.Find(id);
            return HocSinh;
        }

        public int Create(HocSinh HocSinh)
        {
            try
            {
                db.HocSinh.Add(HocSinh);
                return db.SaveChanges();
            }
            catch (Exception ex)
            {
                return 0;
            }
        }

        public int Edit(HocSinh HocSinh)
        {
            try
            {
                db.Entry(HocSinh).State = EntityState.Modified;
                return db.SaveChanges();
            }
            catch (Exception ex)
            {
                return 0;
            }
        }

        public int Delete(int id)
        {
            try
            {
                HocSinh HocSinh = db.HocSinh.Find(id);
                db.HocSinh.Remove(HocSinh);
                return db.SaveChanges();
            }
            catch (Exception ex)
            {
                return 0;
            }
        }

        public List<HocSinh> GetByPhuHuynh(PhuHuynh PhuHuynh)
        {
            var query = from hocsinh in db.HocSinh where hocsinh.PhuHuynh == PhuHuynh select hocsinh;
            List<HocSinh> lstHocSinh = query.ToList<HocSinh>();
            return lstHocSinh;
        }

        public List<HocSinh> GetByLopHoc(int IdLopHoc)
        {
            var query = from hocsinh in db.HocSinh where hocsinh.IdLopHoc == IdLopHoc select hocsinh;
            List<HocSinh> lstHocSinh = query.ToList<HocSinh>();
            return lstHocSinh;
        }

        public List<HocSinh> GetByLopHoc_PhuHuynh(LopHoc LopHoc, PhuHuynh PhuHuynh)
        {
            var query = from hocsinh in db.HocSinh where hocsinh.LopHoc == LopHoc && hocsinh.PhuHuynh == PhuHuynh select hocsinh;
            List<HocSinh> lstHocSinh = query.ToList<HocSinh>();
            return lstHocSinh;
        }
    }
}